package fruit;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class Store {
    static Shop[] shops = new Shop[5];

    static {
        shops[0] = new Shop("牙刷",1,8.8);
        shops[1] = new Shop("毛巾",2,10.0);
        shops[2] = new Shop("水杯",3,18.8);
        shops[3] = new Shop("苹果",4,12.5);
        shops[4] = new Shop("香蕉",5,12.5);
    }
    public static void main(String[] args) {
        show(shops);
        Person p1 = new Person("软21-1 宁伟");
        HashMap<Shop, Integer> s1 = p1.buyGoods(shops);
        count(s1, p1);
        for(int i = 0;i<1000;i++) {
            System.out.println("是否继续购物？输入Y继续，按任意键结束");
            Scanner sc = new Scanner(System.in);
            String ret1 = sc.next();
            if (ret1=="Y"||ret1=="y") {
                break;
            }else{
                Person p2 = new Person();
                HashMap<Shop, Integer> s2 = p2.buyGoods(shops);
                count(s2, p2);
            }
        }
    }
    public static void show(Shop[] shops){
        System.out.println("编号\t商品名称\t价格（元）");
        for(int i = 0;i<shops.length;i++){
            System.out.println(shops[i].getId()+"\t"+shops[i].getName()+"\t"+"\t"+shops[i].getPrice());
        }

    }
    public static void count(HashMap<Shop,Integer> shopList,Person p1){
        double total = 0;
        Set<Shop> set = shopList.keySet();
        Random random = new Random();
        int orderNum = random.nextInt();
        System.out.println("订单编号："+Math.abs(orderNum));
        System.out.println("购物时间："+ LocalDateTime.now());
        System.out.println("会员："+p1.getName());
        for(Shop shop:set){
            int number = shopList.get(shop);
            total+= shop.getPrice() * number;
            System.out.println(shop.getName()+",单价："+shop.getPrice()+",购买数量："+number);

        }
        System.out.println("------------------------------------------------------------");
        System.out.println("\t\t总计："+total);
    }



}

